<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Search extends MX_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->model('search_model');
    }
    
    function index() {
        $txtSearch = $this->input->post('txtSearch');
        $result_center = $this->search_model->getCenterForSearch($txtSearch);
        $result_act = $this->search_model->getActForSearch($txtSearch);
        $result_addr = $this->search_model->getAddrForSearch($txtSearch);
        
        if ($result_center == NULL && $result_act == NULL && $result_addr == NULL) {
            echo 'Không tìm thấy';
        }
        else{
            $str = '';
            if($result_center != NULL){
                    $str = $str."<div class='well well-sm element-search'><span class='glyphicon glyphicon-home'></span><b>Trung tâm</b></div>";
                    foreach ($result_center as $center){
                    $str = $str . "<a href=" . site_url('website/center/loadById/') . '/' . $center['id_center'] . ">"
                            . "<div id='one-result' class='line-result' >"
                            . "<div style='float: left' id='one-result-left'>"
                            . "<img class='img-thumbnail' style='height: 50px; width: 50px;' src='" . base_url($center['url_image']) . "'/>"
                            . "</div>"
                            . "<div style='float: left; width: 270px;' id='one-result-right'>"
                            . "<p>" . $center['name'] . "</p>"
                            . "</div>"
                            . "<div style='clear: left'></div>"
                            . "</div></a>";
                    };
                    
            }
            
            if($result_act != NULL)
            {
                $str = $str."<div class='well well-sm element-search'><span class='glyphicon glyphicon-flag'></span><b>Hoạt động</b></div>";
                foreach ($result_act as $act) {
                $str = $str . "<a href=" . site_url('website/activity/load_by_id/') . '/' . $act['id_activity'] . ">"
                        . "<div id='one-result' class='line-result'>"
                        . "<div style='float: left' id='one-result-left'>"
                        . "<img class='img-thumbnail' style='height: 50px; width: 50px;' src='" . base_url($act['url_image']) . "'/>"
                        . "</div>"
                        . "<div style='float: left; width: 270px;' id='one-result-right'>"
                        . "<p>" . $act['name'] . "</p>"
                        . "</div>"
                        . "<div style='clear: left'></div>"
                        . "</div></a>";
                };
            }
            if($result_addr != NULL)
            {
                $str = $str."<div class='well well-sm element-search'><span class='glyphicon glyphicon-flag'></span><b>Địa điểm</b></div>";
                foreach ($result_addr as $addr) {
                $str = $str . "<a href=" . site_url('website/center/loadById/') . '/' . $addr['id_center'] . ">"
                        . "<div id='one-result' class='line-result'>"
                        . "<div style='float: left' id='one-result-left'>"
                        . "<img class='img-thumbnail zoom' style='height: 50px; width: 50px;' src='" . base_url($addr['url_image']) . "'/>"
                        . "</div>"
                        . "<div style='float: left; width: 270px;' id='one-result-right'>"
                        . "<p>" . $addr['num'] .", ".$addr['street'].", ".$addr['ward'].", ".$addr['district']."</p>"
                        . "</div>"
                        . "<div style='clear: left'></div>"
                        . "</div></a>";
                };
            }
            echo $str;
        }
    }
}
